package com.kd.service.recruiter.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kd.bean.admin.AdminRec;
import com.kd.bean.recruiter.Company_msg;
import com.kd.bean.recruiter.Recruiter_basic;
import com.kd.bean.recruiter.Recruitment_msg;
import com.kd.dao.admin.IAdminRecDao;
import com.kd.dao.recruiter.IRecruitment_msgDao;
import com.kd.service.recruiter.IRecruitment_msgService;

@Service
@Transactional
public class Recruitment_msgServiceImpl implements IRecruitment_msgService{

	@Autowired
	private IRecruitment_msgDao recDao;
	
	@Autowired
	private IAdminRecDao adminRecDao;//管理员相关的类 --管理员-招聘者->我的消息（AdminRec）--
	
	@Override
	public PageInfo<Recruitment_msg> queryAllByRecruitment_msg(Integer pageNum, Integer pageSize,Map<String, Object> map) throws Exception {
		PageHelper.startPage(pageNum, pageSize);
		List<Recruitment_msg> list = recDao.queryAllByRecruitment_msg(map);
		PageInfo<Recruitment_msg> info = new PageInfo<>(list);
		return info;
	}

	@Override
	public Boolean updateRec_msg_state(Integer rec_id, Integer msg_state) {
		
		return recDao.updateRec_msg_state(rec_id, msg_state)>0;
	}

	@Override
	public PageInfo<Recruitment_msg> queryAllRecruitment_msg(Integer pageNum, Integer pageSize) throws Exception {
		PageHelper.startPage(pageNum, pageSize);
		List<Recruitment_msg> list = recDao.queryAllRecruitment_msg();
		PageInfo<Recruitment_msg> info = new PageInfo<>(list);
		return info;
	}

	@Override
	public PageInfo<Recruitment_msg> queryGGFaBuZhaoPingMessage(Integer pageNum, Integer pageSize)
			throws Exception {
		PageHelper.startPage(pageNum, pageSize);
		List<Recruitment_msg> list = recDao.queryGGFaBuZhaoPingMessage();
		PageInfo<Recruitment_msg> info = new PageInfo<>(list);
		return info;
	}

	@Override
	public Boolean updateFaBuZhaoPingMessagRec_msg_check_state(Integer rec_id, Integer rec_msg_check_state,
			Integer admin_id) throws Exception {
		Recruitment_msg recruitment_msg = recDao.queryByRec_id(rec_id);//查看招聘信息
		if(rec_msg_check_state==1) {
			//管理员给招聘者发送被审核成功的消息
			AdminRec adminRec = new AdminRec();
			adminRec.setRecruiter_id(recruitment_msg.getRecruiter_basic().getRecruiter_id());//招聘者id
			adminRec.setAdminRec_news_context("您旗下的招聘信息通过审核");//消息内容
			adminRec.setAdmin_id(admin_id);
			adminRecDao.insertRecJuBaoMessage(adminRec);
		}else if(rec_msg_check_state==2){
			//管理员给招聘者发送被审核失败的消息
			AdminRec adminRec = new AdminRec();
			adminRec.setRecruiter_id(recruitment_msg.getRecruiter_basic().getRecruiter_id());//招聘者id
			adminRec.setAdminRec_news_context("您旗下的招聘信息未通过审核");//消息内容
			adminRec.setAdmin_id(admin_id);
			adminRecDao.insertRecJuBaoMessage(adminRec);
		}
		return recDao.updateFaBuZhaoPingMessagRec_msg_check_state(rec_id, rec_msg_check_state)>0;
	}

	@Override
	public Integer queryJobCount() throws Exception {
		
		return recDao.queryJobCount();
	}

	@Override
	public Integer queryNowJobCount() throws Exception {
		
		return recDao.queryNowJobCount();
	}

	@Override
	public PageInfo<Recruitment_msg> queryAllRecMsgByRecruiter_id(Integer pageNum, Integer pageSize,
			Integer recruiter_id) throws Exception {
		PageHelper.startPage(pageNum, pageSize);
		List<Recruitment_msg> list = recDao.queryAllRecMsgByRecruiter_id(recruiter_id);
		PageInfo<Recruitment_msg> info = new PageInfo<>(list);
		return info;
	}

	@Override
	public Boolean removeRecMsgByRecruiter_id(Integer rec_id) throws Exception {
		
		return recDao.removeRecMsgByRecruiter_id(rec_id)>0;
	}

	@Override
	public Boolean insertRecMsg(Recruitment_msg recMsg,Recruiter_basic basic,Company_msg company) throws Exception {
		recMsg.setRecruiter_id(basic.getRecruiter_id());//关联招聘者id',
		recMsg.setRec_name(basic.getRecruiter_name()); //招聘信息的招聘者姓名
		recMsg.setRec_phone(basic.getRecruiter_phone()); //招聘信息的招聘者联系电话
		recMsg.setRec_company_name(company.getCompany_name()); //公司名
		recMsg.setRec_company_address(company.getCompany_address()); //公司地址
		recMsg.setCreate_time(new Date());
		return recDao.insertRecMsg(recMsg)>0;
	}

	@Override
	public Recruitment_msg queryByRec_id(Integer rec_id) throws Exception {
		
		return recDao.queryByRec_id(rec_id);
	}


}
